package com.ty.servlet;

import cn.hutool.core.date.StopWatch;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

//@WebFilter("/*")
@Slf4j
public class LogFilter  implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        chain.doFilter(request, response);
        stopWatch.stop();
        HttpServletRequest httpServletRequest =   (HttpServletRequest) request;
        String url = httpServletRequest.getRequestURI().toString();
        log.debug("{} 总耗时：{} ms",url,stopWatch.getTotalTimeMillis());

        //
    }
}
